39
Easy2Siksha
The Moral of the Story
Think of continue as a "skip" button and break as a "stop" button:
• Use continue when you want to skip unnecessary steps and focus on the next ones.
• Use break when you want to stop everything and exit the loop immediately.
6. What is Function? What are differences between passing an array to a function and
passing a single-valued data item to a function? Explain using example.
Ans: What is a Function?
In simple terms, a function is a block of code or a set of instructions that performs a specific
task in a program. Functions are used to break down large, complex problems into smaller,
manageable parts, making the code easier to read, maintain, and reuse.
Imagine a function as a machine. For instance, a washing machine is designed to wash
clothes. When you want to use it, you give it inputs (like clothes, detergent, and water), and
it performs its task (washing the clothes). Similarly, in programming, a function may take
some input, process it, and then give an output.
Key Points about Functions:
1. Reusability: Functions can be used multiple times, so you don’t have to write the
same code repeatedly.
2. Modularity: Programs become organized because functions can handle specific tasks
independently.
3. Ease of Debugging: If there is an error in a function, you only need to fix that
particular function without affecting the rest of the code.
4. Clarity: Functions make the code cleaner and easier to understand.
Types of Functions
1. Built-in Functions: These are predefined in programming languages. For example, in
C, printf() is a built-in function used to display output.
2. User-defined Functions: These are created by programmers for specific tasks. For
example, if you want to calculate the square of a number, you can write a function
for it.
Passing Data to a Function
When you use a function, you often give it some inputs, called arguments or parameters, to
work with. These inputs can be either: